package leetcode_2501_2600;

public class LeeCode_2511 {
    public static void main(String[] args) {

    }
    private static int captureForts(int[] forts) {
        int n = forts.length, ans = 0;
        for (int i = 0; i < n; i++) {
            if (forts[i] == 1){
                int j = i - 1, c = 0;
                boolean flag = false;
                while (j >= 0){
                    if (forts[j] == 0){
                        c++;
                    }else if (forts[j] == -1){
                        flag = true;
                        break;
                    }else {
                        break;
                    }
                    j--;
                }
                if (flag) {
                    ans = Math.max(ans, c);
                }
                flag = false;
                j = i + 1;
                c = 0;
                while (j < n){
                    if (forts[j] == 0){
                        c++;
                    }else if (forts[j] == -1){
                        flag = true;
                        break;
                    }else {
                        break;
                    }
                    j++;
                }
                if (flag) {
                    ans = Math.max(ans, c);
                }
            }
        }
        return ans;
    }
}
